package com.hcinfos.gsoo.ui;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.hcinfos.gsoo.R;
import com.hcinfos.gsoo.adapter.MenuAdapter;
import com.hcinfos.gsoo.adapter.MenuDetailAdapter;
import com.hcinfos.gsoo.adapter.MenuScrollViewAdapter;
import com.hcinfos.gsoo.enity.GdMealsDish;
import com.hcinfos.gsoo.enity.WType;
import com.hcinfos.gsoo.interfaze.DataCallback;

/**
 * 菜单 菜页面
 * 
 * @author xi
 * 
 */
public class DingZuoMenuActivity extends Activity implements OnClickListener {

	private ListView menu_listView;
	private ListView menuDetail_listView;
	private MenuAdapter menuAdapter;
	private MenuDetailAdapter menuDetailAdapter;

	private List<WType> menuList;
	private List<GdMealsDish> menuDetailList;
	private ImageView up_iv;

	private RelativeLayout scroll_rl;
	private ImageView left_arrow_iv;

	private ViewPager viewPager;
	private MenuScrollViewAdapter pagerAdapter;

	private TextView order_tv;

	private Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_dingzuomenu);
		initRes();
	}

	private void initRes() {

		order_tv = (TextView) findViewById(R.id.order_tv);
		order_tv.setOnClickListener(this);
		menu_listView = (ListView) findViewById(R.id.menu_listView);
		menuDetail_listView = (ListView) findViewById(R.id.menuDetail_listView);

		menuList = new ArrayList<WType>();
		menuDetailList = new ArrayList<GdMealsDish>();

		// scroll_rl.setVisibility(View.VISIBLE);
		// menuAdapter = new MenuAdapter(this, menuList);
		menuDetailAdapter = new MenuDetailAdapter(this, menuDetailList);
		menu_listView.setAdapter(menuAdapter);
		menu_listView.setOnItemClickListener(menuItemOnClickListener);
		menuDetail_listView.setAdapter(menuDetailAdapter);
		menuDetail_listView
				.setOnItemClickListener(menuDetailItemOnClickListener);
		testData();
		// menuAdapter.setDataChange(menuList);
		menuDetailAdapter.setDataChange(menuDetailList);

		scroll_rl = (RelativeLayout) findViewById(R.id.scroll_rl);
		scroll_rl.setBackgroundColor(Color.argb(200, 0, 0, 0));
		scroll_rl.setOnClickListener(this);
		scroll_rl.setVisibility(View.GONE);
		left_arrow_iv = (ImageView) findViewById(R.id.left_arrow_iv);
		left_arrow_iv.setOnClickListener(this);

		viewPager = (ViewPager) findViewById(R.id.viewPager);
		pagerAdapter = new MenuScrollViewAdapter(menuDetailList, this,
				new DataCallback() {

					@Override
					public void callback(int command) {
						scroll_rl.setVisibility(View.GONE);
					}
				});
		viewPager.setAdapter(pagerAdapter);

	}

	private void testData() {

	}

	OnItemClickListener menuDetailItemOnClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {

			scroll_rl.setVisibility(View.VISIBLE);
		}
	};

	OnItemClickListener menuItemOnClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int position,
				long arg3) {

			menuAdapter.setSelect(position);
		}
	};

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.scroll_rl:
			if (scroll_rl.getVisibility() == View.VISIBLE) {
				scroll_rl.setVisibility(View.GONE);
			}
			break;
		case R.id.left_arrow_iv:
			Toast.makeText(this, "test", 500).show();
			break;
		case R.id.order_tv:
			intent = new Intent(this, DingZuoOrderConfirActivity.class);
			startActivity(intent);
			break;
		}
	}

}
